<?php
/**
 * Created by PhpStorm.
 * User: lx
 * Date: 2020/1/14
 * Time: 21:18
 */
namespace app\api\controller;

use app\api\model\MtUserLivePeople;
use app\util\ReturnCode;

/**
 * 入住用户
 * Class UserPeople
 * @package app\api\controller
 */
class UserPeople extends Base
{
    /**
     * 入住人口信息添加
     */
    public function addPeople(){
        $data['userID'] = intval($this->request->param("userID"));
        $data['trueName'] = $this->request->post("trueName");
        $data['tel'] = $this->request->post('tel');
        $data['IDCard'] = $this->request->post("idCard");
        if(!$data['trueName'] || !$data['tel'] || $data['idCard']){
            return $this->error(ReturnCode::EMPTY_PARAMS,"缺少参数");
        }
        $data['sex '] = intval($this->request->post("sex")) ? intval($this->request->post("sex")) : 1;
        $data['birthday'] = $this->request->post("birthday") ? $this->request->post("birthday") : "";
        $data['cTime'] = time();
        $res = (new MtUserLivePeople())->insert($data,true);
        if(!$res){
            return $this->error(ReturnCode::DB_SAVE_ERROR,"people添加失败");
        }
        return $this->success("添加成功");
    }

    /**
     * 入住人口信息删除
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function peopleDel(){
        $id = intval($this->request->get("id"));
        if(!$id){
            return $this->error(ReturnCode::EMPTY_PARAMS,"缺少参数");
        }
        $res = (new MtUserLivePeople())->where("id",$id)->delete();
        if(!$res){
            return $this->error(ReturnCode::DB_SAVE_ERROR,"people删除失败");
        }
        return $this->error(ReturnCode::DB_SAVE_ERROR,"people删除成功");
    }
}